package com.zh.home

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts
import com.zh.common.base.BaseActivity
import com.zh.common.ktx.clickSingleListener
import com.zh.common.ktx.setResult
import com.zh.common.ktx.toast
import com.zh.home.databinding.ActivityINextBinding

class INext : BaseActivity<ActivityINextBinding>() {

    override fun initView(savedInstanceState: Bundle?) {
        viewBinding.tvName.text = intent.getStringExtra("name")?:"王五"
//        setResult(Activity.RESULT_OK, Intent().putExtra("name", "张三"))
        setResult {
            putExtra("name", "张三")
        }

       val startActivity =
            registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
                if (Activity.RESULT_OK == it.resultCode) {
                    toast(it.data?.getStringExtra("name"))
                }
            }
        viewBinding.tvName.clickSingleListener {
            startActivity.launch(Intent(this, INext::class.java).putExtra("name", "李四"))
        }
    }
}